<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>库存管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--列表-->
    <el-table size="small" :data="numList" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" prop="id" label="商品ID" width="150">
      </el-table-column>
      <el-table-column align="center" prop="goodsName" label="商品名" width="150">
      </el-table-column>
      <el-table-column align="center" prop="coverImg" label="货品图" width="150">
        <template slot-scope="scope" v-if="scope.row.coverImg">
          <el-image
            style="width: 100px"
            :src="scope.row.coverImg"
            fit="contain"></el-image>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" prop="originalPrice" label="进价" width="150"></el-table-column>
      <el-table-column sortable align="center" prop="sellPrice" label="售价" width="150"></el-table-column>
      <el-table-column align="center" prop="inventory" label="当前库存" width="150">
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="discNum(scope.$index, scope.row)">修改库存</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageQuery" @callFather="callFather"></Pagination>
    <el-dialog title="修改库存" :visible.sync="dialog" width="30%">
      <el-input-number v-model="good.inventory" @change="handleChange" :min="0"  style="width: 50%;"></el-input-number>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" :loading="loading" class="title" @click="sureChange">确认修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
export default {
  name:'ManagerNum',
  data() {
    return {
      good: {},
      dialog: false, 
      numList: [], // 库存列表
      pageQuery: {
        pageNum: 1,
        pageSize: 10
      },
      loading: false //是显示加载
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getNumList()
  },
  methods: {
    /**
     * 获取用户列表
     */
    getNumList() {
      this.loading = true
      this.$api.manager.getGoodsList(this.pageQuery).then(res => {
        if (res.code === 200) {
          this.numList = res.data.records
          this.loading = false
        }
      }).catch(err => this.loading = false)
    },
    /**
     * 分页插件事件
     */
    callFather(parm) {
      this.pageQuery.pageNum = parm.currentPage
      this.pageQuery.pageSize = parm.pageSize
      this.getCommentList(this.pageQuery)
    },
    /**
     * 修改库存
     */
    handleChange (val) {
    },
    sureChange () {
      let query = {
        id: this.good.id,
        inventory: this.good.inventory
      }
      this.$api.manager.discGood(query).then(res => {
        if (res.code === 200) {
          this.getNumList()
          this.dialog = false
        }
      })
    },
    /**
     * 修改库存
     */
    discNum (index, comment) {
      this.dialog = true
      this.good = comment
    }
  }
}
</script>

<style>
.comment-search {
  margin-top: 20px;
}
.commentRole {
  width: 100%;
}
</style>

 
 